// 获取文集
import pool from '@/server/db'
import { RowDataPacket } from 'mysql2'

export default defineEventHandler(async event => {
  // 判断用户是否登录
  if (!event.context.userinfo) return r('请登录')
  const { uid } = event.context.userinfo

  // 查询文集
  try {
    const [rows] = await pool.execute(
      'SELECT * FROM `notebooks` WHERE `uid` = ?',
      [uid]
    )
    if ((rows as RowDataPacket[]).length < 1) {
      return r('查询文集失败')
    }
    return r('查询成功', 1, rows)
  } catch (error) {
    return r('文集查询失败:' + error)
  }
})
